{# emit a * for every slash so they can be counted #}
{%- macro countslashes(str) %}
  {%- set slashcount = 0 %}
  {%- for char in str %}
    {%- if char == '/' -%}
      *
    {%- endif %}
  {%- endfor -%}
{%- endmacro %}
{%- set slashcount =  countslashes(pagename)|length %}

{%- macro examplename(str) %}
  {%- set slashcount = 0 %}
  {%- for char in str %}
    {%- if char == '/' -%}
      {%- set slashcount = slashcount + 1 %}
    {%- else %}
      {%- if slashcount > 2 and slashcount < 4 %}{{ char }}{%- endif %}
    {%- endif %}
  {%- endfor -%}
{%- endmacro %}
{%- set archivename = examplename(pagename)%}

{%- if prev %}
  {%- if slashcount == 4 %}
  <li>
    <a href="{{ prev.link|e }}" title="{{ _('Previous example: ') + prev.title|striptags }}">
      {%- if theme_bootstrap_version == "2" -%}<span class="icon-chevron-left visible-tablet"></span>{%- endif -%}
      {%- if theme_bootstrap_version == "3" -%}<span class="glyphicon glyphicon-chevron-left visible-sm"></span>{%- endif -%}
      <span class="hidden-sm hidden-tablet">{{ "&laquo;"|safe }} Previous example</span>
    </a>
  </li>
  {%- else %}
  <li>
    <a href="{{ prev.link|e }}" title="{{ _('Previous topic: ') + prev.title|striptags }}">
      {%- if theme_bootstrap_version == "2" -%}<span class="icon-chevron-left visible-tablet"></span>{%- endif -%}
      {%- if theme_bootstrap_version == "3" -%}<span class="glyphicon glyphicon-chevron-left visible-sm"></span>{%- endif -%}
      <span class="hidden-sm hidden-tablet">{{ "&laquo;"|safe }} {{ prev.title|striptags|truncate(length=16, killwords=True) }}</span>
    </a>
  </li>
  {%- endif %}
{%- endif %}
{%- if next %}
  {%- if slashcount == 4 %}
  <li>
    <a href="{{ next.link|e }}" title="{{ _('Next example: ') + next.title|striptags }}">
      {%- if theme_bootstrap_version == "2" -%}<span class="icon-chevron-right visible-tablet"></span>{%- endif -%}
      {%- if theme_bootstrap_version == "3" -%}<span class="glyphicon glyphicon-chevron-right visible-sm"></span>{%- endif -%}
      <span class="hidden-sm hidden-tablet">Next example {{ "&raquo;"|safe }}</span>
    </a>
  </li>
  {%- else %}
  <li>
    <a href="{{ next.link|e }}" title="{{ _('Next topic: ') + next.title|striptags }}">
      {%- if theme_bootstrap_version == "2" -%}<span class="icon-chevron-right visible-tablet"></span>{%- endif -%}
      {%- if theme_bootstrap_version == "3" -%}<span class="glyphicon glyphicon-chevron-right visible-sm"></span>{%- endif -%}
      <span class="hidden-sm hidden-tablet">{{ next.title|striptags|truncate(length=16, killwords=True) }} {{ "&raquo;"|safe }}</span>
    </a>
  {%- endif %}
{%- endif %}


{%- if slashcount == 4 %}
  <li class="dropdown">
    <a href="{{ meta.get("name") ~ ".zip" }}">
    <span class="glyphicon glyphicon-download-alt"></span> <span class="hidden-sm hidden-tablet">&nbsp; {{ _('Download') }}</span>
    </a>
  </li>
{%- endif %}


<canvas id="testCanvas" width="8" height="8" hidden>
</canvas>
